<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!DOCTYPE html>
<html>
<head>
	<jsp:include page="../inc_min.jsp"></jsp:include>
	<link rel="stylesheet" href="${ctx}/css/orderQuery.css"/>
	<link rel="stylesheet" href="${ctx}/css/iconfont.css"/>
<title>订单查询</title>
<script type="text/javascript">
	$(function() {
        getData();
		//点击查询 重新加载列表
		$("#query").click(function(){
            pageNum = 1;
            getData();
		});
	});
    var pageNum = 1;
	function getData(){
        //出发到达城市清空处理
        alsoempty($("#homecity_name"),$("#_startCity"));
        alsoempty($("#getcity_name"),$("#_endCity"));
        //获取参数
        var orderNumber=$("#_orderNumber").val();
        var orderStatus=$("#orderStatus").val();
        var toStartAirportCode=$("#_startCity").val();
        var toEndAirportCode=$("#_endCity").val();
        var toStartDate=$("#startDate").val();
        var toEndDate=$("#endDate").val();
        if(typeof(toStartAirportCode) == 'undefined'){
            toStartAirportCode = "";
        };
        if(typeof(toEndAirportCode) == 'undefined'){
            toEndAirportCode = "";
        };
        var param = {
            "orderNumber":orderNumber,
            "orderStatus":orderStatus,
            "toStartAirportCode":toStartAirportCode,
            "toEndAirportCode":toEndAirportCode,
            "toStartDate":toStartDate,
            "toEndDate":toEndDate,
            "page":pageNum,
            "rows":20
        }
        $.get('${ctx}/search/getBuyerList?orderType=0&temp='+Math.random(),param,function(data){
            $('table tbody').empty();
            var str = "";
            for(var i=0;i<data.rows.length;i++){
                var obj = data.rows[i];
                var tablebutton = "";
                var time=obj.payOverTime;
                var intervalDay=CommonConverter.toEmptyStr(obj.list[0].intervalDay);
                if(intervalDay != 0){
                	intervalDay ="+"+intervalDay;
                };
                if(time == null || time == undefined){
                    time="";
                }else{
                    time=time.replace(" ","=");
                };
	            var operation='<i class="icon iconfont position" title="详情" onclick=orderDtail("'+obj.orderNumber+'")>&#xe62d;</i>';
                if(obj.orderStatus==0){  //待支付状态时 显示支付押金按钮
                	operation +="<span class='add_minus right' style='padding:0 0;height:25px;margin-right:15px;line-height:25px;' onclick=orderTicket('"+obj.orderNumber+"')>支付并下单</span>";
                    //待支付状态时  显示倒计时
                    var timeId = "time"+obj.orderNumber;
                    var timeSec = new Date();
                    if(timeSec>0){
                        var startTime = new Date();
                        //调用置指定时间的毫秒字段
                        var EndTime=startTime.getTime();
                       // var timer_rt = window.setInterval("GetRTime("+EndTime+",'"+timeId+"')", 1000);
                    };
                    timeOut='<span style="color:#ff8800;">'+CommonConverter.toOrderBizStatusStr(obj.orderStatus)+'</span>';//<img src="${ctx}/image/delay_out.png" style="vertical-align:middle"><br/>剩余保留时间：<span id="'+timeId+'"></span>';
                }else{
                    timeOut=CommonConverter.toOrderBizStatusStr(obj.orderStatus);
                };
                str+="<tr height='38px' class='reBorder'>"
                str+="		<td width='246px' align='center'>订单号："+obj.orderNumber+"</td>"
                str+="		<td width='117px' align='right' colspan='7'>"+operation+"</td>"
                str+="</tr>"
                str+="<tr height='90px'>"
                str+="	<td width='128px' align='right'>"
                str+="		往：<span style='color:black;'>"+obj.list[0].airlineNumber+"</span><br/>"
                str+= (obj.list.length==2) ?  "返：<span style='color:black;'>"+obj.list[1].airlineNumber+"</span>" :  "";
                str+="	</td>"
                str+="	<td width='197px' align='right'>"
                str+="		<span>"+CommonConverter.formatFlightTime((obj.list)[0].deptTime)+"</span><br/>"
                str+="		<span style='color:#444e50'>"+obj.list[0].deptCity+"</span><span style='color:#444e50'>("+obj.list[0].deptCode+")</span><span style='color:#e2615c'>"+obj.list[0].deptTerminal+"</span><br/>"
                str+= (obj.list.length==2) ?  "<span>"+CommonConverter.formatFlightTime((obj.list)[1].arrTime)+"</span><br/>" :  "";
                str+="	</td>"
                str+="	<td width='169px' align='center'>"
                str+="		<span style='color:#23b9dc'>"+obj.list[0].deptDate+"</span><br/>"
                str+= (obj.list.length==2) ?  "<img src='${ctx}/image/flightQuery/round.gif'><br/>" :  "<img src='${ctx}/image/flightQuery/dancheng.png'><br/>";
                str+= (obj.list.length==2) ?  "<span style='color:#23b9dc'>"+obj.list[1].deptDate+"</span><br/>" :  "";
                str+="	</td>"
                str+="	<td width='299px'>"
                str+="		<span>"+CommonConverter.formatFlightTime((obj.list)[0].arrTime)+"</span><span style='color:#e2615c;'>"+intervalDay+"<br/>"
                str+="		<span style='color:#444e50'>"+obj.list[0].arrCity+"</span><span style='color:#444e50'>("+obj.list[0].arrCode+")</span><span style='color:#e2615c'>"+obj.list[0].arrTerminal+"</span><br/>"
                str+= (obj.list.length==2) ?  "<span>"+CommonConverter.formatFlightTime((obj.list)[1].deptTime)+"</span><br/>" :  "";
                str+="	</td>"
                str+="	<td width='160px' align='center' style='color:#444e50'>"+obj.sellingPrice+"</td>"
                str+="	<td width='134px' align='center' style='color:#444e50'>"+obj.purchQuantity+"</td>"
                str+="	<td width='127px' align='center' style='color:#e2615c'>"+obj.sum+"</td>"
                str+="	<td width='86px' align='center' style='color:#23b9dc'><span>"+timeOut+"</span></td>"
                str+="</tr>"
            }
            $('#tbody').append(str);
            //显示分页
            layui.use(['laypage', 'layer'], function(){
                var laypage = layui.laypage;
                laypage({
                    cont: 'pager'
                    ,pages:  Math.ceil(data.total/20) //得到总页数 //总页数
                    ,groups: 5 //连续显示分页数
                    ,skin: '#1E9FFF'
                    ,curr : pageNum
                    ,jump: function(obj,first){
                        if(!first){
                            pageNum = obj.curr;
                            getData();
                        }
                    }
                });
            });
        })
    }
	
	
	
	//订单支付
	function OrderPay(orderNumber) {
		window.location.href='${ctx}/order/orderPay/'+orderNumber;
	}; 
	//查看票号弹出框
	function getTickedDetail(orderNumber) {
		//console.log(orderNumber)
		layer.open({
			type: 2,
			title: ['订单管理-查看票号','background-color:#00B2EE; color:#fff;'],
			shadeClose: true,
			shade: 0.3,
			area: ['1020px', '500px'],  
			content: ['${ctx}/order/orderTickets/'+orderNumber, 'no'], //iframe的url，no代表不显示滚动条
		});
	};
	//出票申请
	function orderTicket(orderNumber){
		window.location.href='${ctx}/np/orderPassengerWait/'+orderNumber;
	}
	//取消订单
	function cancelOrder(orderNumber){
		layer.confirm("确认要取消订单【"+orderNumber+"】吗？"
			, {title:['取消订单','background-color:#00B2EE; color:#fff;'],area: ['400px', '150px']}
			, function(index){
				$.ajax({
				    type:'get',
				    url: '${ctx}/order/cancel/'+orderNumber+'?t='+Math.random(),
				    success:function(data){
				    	if(data.status==1){
					        layer.alert('取消订单成功！'
					        	,{skin:'layui-layer-lan',title: ['系统提示', 'background-color:#00B2EE; color:#fff;'],closeBtn: 0}
					        	, function(index){
					        		$('#orderTable').datagrid("reload");
					        		$('#orderTable').datagrid('unselectAll');//清除全选
									layer.close(index);
								});
					    }
					    else{
					      layer.alert(data.message);
					    }
				    },
				    error:function(msg){
				    	layer.alert("请检查您的网络连接，然后重试！");
				    }
				}); 
				
				layer.close(index);
			}
		);
	}; 
	//查看详情
	function orderDtail(orderNumber){
		window.location.href='${ctx}/order/detail/'+orderNumber;
		/* layer.open({
			type: 2,
			title: ['订单管理-查看详情','background-color:#00B2EE; color:#fff;'],
			shadeClose: true,
			shade: 0.3,
			area: ['1200px', '500px'],
			content: ['${ctx}/order/detail/'+orderNumber, 'no'], //iframe的url，no代表不显示滚动条
			success: function(layero, index){
			  layer.full(index);
			}
		}); */
	}; 
	//如果为空  对应的文本框为空
	function alsoempty(a,b){
		if(a.val() == "中文/拼音"){
			b.val("");
		};
	};
</script>
</head>
<body>
<jsp:include page="../head.jsp"></jsp:include>
<div class="content">
		<ul class='list'>
				<li>订单号：<input style='width:120px;' class="easyui-textbox" id="_orderNumber" /></li>
				<li>状态：
					<select id="orderStatus" style="width: 73px;">
						<option value="-1">所有订单</option>
						<option value="0">待支付</option>
						<option value="2">待出票</option>
						<option value="4">出票完成</option>
						<option value="5">已取消</option>
					</select>
				</li>
				<li>出发城市：
					<input type="text" value="" size="15" id="homecity_name" name="homecity_name" style="width:150px;height: 18px" mod="address|notice" mod_address_source="hotel" mod_address_suggest="" mod_address_reference="_startCity" mod_notice_tip="中文/拼音" />
					<input id="_startCity" name="_startCity" type="hidden" value="" />
				</li>
				<li>到达城市：
					<input type="text" value="" size="15" id="getcity_name" name="getcity_name" style="width:150px;height: 18px" mod="address|notice" mod_address_source="hotel"  mod_address_reference="_endCity" mod_notice_tip="中文/拼音" />
					<input id="_endCity" name="_endCity" type="hidden" value="" />
				</li>
				<li>
					出发时间 ：<input type="text" id="startDate" style="height:18px;" class="textbox" value="${requestScope.deptDate}" onFocus="new WdatePicker({dateFmt:'yyyy-MM-dd'})"/>
					<img class="city" src="${ctx}/image/date.gif">&nbsp;&nbsp;&nbsp;&nbsp;
					至<input type="text" style="height:18px;" id="endDate" class="textbox" value="${requestScope.endDate}" onFocus="new WdatePicker({dateFmt:'yyyy-MM-dd'})">
					<img class="city" src="${ctx}/image/date.gif">
				</li>
				<li>
					<button class='query' id="query" >查询</button>
				</li>
		<table class="orderTable" id="tb" >
			<thead>
				<tr height="38px" >
					<td width="128px" align="right">航班号</td>
					<td width="197px" align="right">出发/到达</td>
					<td width="169px" align="center">&nbsp;&nbsp;&nbsp;</td>
					<td width="299px" align="left">到达/出发</td>
					<td width="160px" align="center">单价(CNY)</td>
					<td width="134px" align="center">数量</td>
					<td width="127px" align="center">总价(CNY)</td>
					<td width="86px" align="center">状态</td>
				</tr>
			</thead>
				<tbody id="tbody">

				</tbody>
			</table>
<!-- 分页 -->
<div id="pager" class="divBox"></div>
</div>
<script type="text/javascript" src="${ctx }/jslib/airport/fixdiv.js"></script>
<script type="text/javascript" src="${ctx }/jslib/airport/address.js"></script>
<jsp:include page="../footer.jsp"></jsp:include>
</body>
</html>